const App = {
    mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            page: {
                PageNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("%%")))
            },
        }
    },
    mounted() {

    },
    methods: {
        check(){
            if(this.page.value1){
                this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%")));
            } else {
                this.page.Condition = window.btoa(unescape(encodeURIComponent("%%")));
            }
            this.postgetList(this.page)
        },
        //树的点击筛选事件
        handleNodeClick(data, node) {
            // let str = "";
            // if (node.level == 1) {
            //     if (data.children) {
            //         data.children.forEach(item => {
            //             if (str) {
            //                 str = str + "OR Crop_SerialNumber='" + item.Crop_SerialNumber + "'\r\n";
            //             } else {
            //                 str = "Crop_SerialNumber='" + item.Crop_SerialNumber + "'\r\n";
            //             }
            //         });
            //     } else {
            //         let str = "";
            //         this.$message({
            //             type: 'warning',
            //             message: '暂无作物子类'
            //         });
            //     }
            // } else if (node.level == 2) {
            //     str = "Crop_SerialNumber='" + data.Crop_SerialNumber + "'\r\n";
            // }
            // if (str) {
            //     str = "and (" + str + ")";
            // }
            // this.page.Condition1 = str
            // this.postgetList(this.page);
        },
        handleAdd(row){
            window.location.href = './add.html?action=Add&nodeKey=' + row.Merchant_Category_SerialNumber
        },
        postgetList(page) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    Model_Url: this.relativePath,
                    Condition: page.Condition,
                    PaginationNumber: page.PageNumber,
                    ...page,
                    ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND Parent_SerialNumber=''")))
                },
                success: (res) => {
                    that.Total = res.TotalRows;//总数量
                    that.loading = false;
                    res.Rows.forEach(item => {
                        item.children = [];
                        item.hasChildren = true;
                    });
                    that.Tabletdata = res.Rows;
                    this.$nextTick(() => {
                        // 手动展开一级节点
                        if (this.Tabletdata.length > 0) {
                          this.Tabletdata.forEach(row => {
                            this.$refs.multipleTable.toggleRowExpansion(row, true);
                          });
                        }
                    })
                    let lJSONObject_DataSet = {
                        Add: {
                            base_operation_log: [{
                                Operation_Type: '0',
                                Operation_Path: this.relativePath,
                                Operation_Main:JSON.stringify(deepClone({
                                    Data:res.Rows,
                                    Param:{
                                        Model_Url: this.relativePath,
                                        Condition: page.Condition,
                                        PaginationNumber: page.PageNumber,
                                        ...page,
                                        ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND Parent_SerialNumber=''")))
                                    }
                                })),
                                Operation_Interface: "generalPaginationQueryBySQLSerialNumber",
                                Operation_IP: getIpAddress()
                            }]    
                        }
                    }
                    submitSave(lJSONObject_DataSet)
                    // this.websocket.send(JSON.stringify({ Data: lJSONObject_DataSet, Action: 'Log', AccessToken: getCookie('token') }));
                    // $.ajax({
                    //     headers: requestHeaders("JSON"),
                    //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                    //     method: "post",
                    //     data: JSON.stringify({
                    //         Data: {
                    //             Add: {
                    //                 base_operation_log: [{
                    //                     Operation_Type: '0',
                    //                     Operation_Path: this.relativePath,
                    //                     Operation_Main:JSON.stringify(deepClone({
                    //                         Data:res.Rows,
                    //                         Param:{
                    //                             Model_Url: this.relativePath,
                    //                             Condition: page.Condition,
                    //                             PaginationNumber: page.PageNumber,
                    //                             ...page,
                    //                             ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND Parent_SerialNumber=''")))
                    //                         }
                    //                     })),
                    //                     Operation_Interface: "generalPaginationQueryBySQLSerialNumber",
                    //                     Operation_IP: getIpAddress()
                    //                 }]    
                    //             }
                    //         },
                    //     }),
                    //     complete: (XMLHttpRequest) => {
                    //         requestPretreatment(XMLHttpRequest)
                    //     }
                    // });
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                }
            });
        },
        load(tree, treeNode, resolve){
            console.log(tree.Merchant_Category_SerialNumber);
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    Model_Url: this.relativePath,
                    Condition: window.btoa(unescape(encodeURIComponent("%%"))),
                    ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND Parent_SerialNumber='"+ tree.Merchant_Category_SerialNumber+"'")))
                },
                success: (data) => {
                    console.log(data);
                    resolve(data)
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                }
            });
            
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
